﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace library
{
    public partial class change_rules : Form
    {
        public MySqlConnection conn = new DBclass().getConn();
        public change_rules()
        {
            InitializeComponent();
        }

        private void change_rules_Load(object sender, EventArgs e)
        {
            conn.Open();
            string sql = "select rname,mag from fine_rule";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            DataSet ds = new DataSet();
            MySqlDataAdapter da = new MySqlDataAdapter(cmd);
            da.Fill(ds);
            DataTable dataTable = ds.Tables[0];
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dataTable;
            this.dataGridView1.Columns["规则名称"].DataPropertyName = dataTable.Columns["rname"].ToString();
            this.dataGridView1.Columns["倍率"].DataPropertyName = dataTable.Columns["mag"].ToString();
            conn.Close();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex>=0)
            {
                DataGridViewColumn c = dataGridView1.Columns[e.ColumnIndex];
                if(c is DataGridViewButtonColumn)
                {
                    string rname = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    string mag = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                    change_do f = new change_do(rname,mag);
                    f.Show();
                }
            }
        }
    }
}
